<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
  Class: KnifeGithubCleanup::GithubCleanup

    &mdash; Knife Github utilities

</title>

  <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />

  <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  hasFrames = window.top.frames.main ? true : false;
  relpath = '../';
  framesUrl = "../frames.html#!" + escape(window.location.href);
</script>


  <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>


  </head>
  <body>
    <div id="header">
      <div id="menu">

    <a href="../_index.html">Index (G)</a> &raquo;
    <span class='title'><span class='object_link'><a href="../KnifeGithubCleanup.html" title="KnifeGithubCleanup (module)">KnifeGithubCleanup</a></span></span>
     &raquo;
    <span class="title">GithubCleanup</span>


  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">

    <a class="full_list_link" id="class_list_link"
        href="../class_list.html">
      Class List
    </a>

    <a class="full_list_link" id="method_list_link"
        href="../method_list.html">
      Method List
    </a>

    <a class="full_list_link" id="file_list_link"
        href="../file_list.html">
      File List
    </a>

</div>
      <div class="clear"></div>
    </div>

    <iframe id="search_frame"></iframe>

    <div id="content"><h1>Class: KnifeGithubCleanup::GithubCleanup



</h1>

<dl class="box">

    <dt class="r1">Inherits:</dt>
    <dd class="r1">
      <span class="inheritName"><span class='object_link'><a href="../Chef/Knife.html" title="Chef::Knife (class)">Chef::Knife</a></span></span>

        <ul class="fullTree">
          <li>Object</li>

            <li class="next"><span class='object_link'><a href="../Chef/Knife.html" title="Chef::Knife (class)">Chef::Knife</a></span></li>

            <li class="next">KnifeGithubCleanup::GithubCleanup</li>

        </ul>
        <a href="#" class="inheritanceTree">show all</a>

      </dd>









    <dt class="r2 last">Defined in:</dt>
    <dd class="r2 last">lib/chef/knife/github_cleanup.rb</dd>

</dl>
<div class="clear"></div>









    <h2>
      Instance Method Summary
      <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
    </h2>

    <ul class="summary">

        <li class="public ">
  <span class="summary_signature">

      <a href="#repo_cleanup-instance_method" title="#repo_cleanup (instance method)">- (Object) <strong>repo_cleanup</strong>(repo) </a>



  </span>









    <span class="summary_desc"><div class='inline'></div></span>

</li>


        <li class="public ">
  <span class="summary_signature">

      <a href="#repo_status_clean%3F-instance_method" title="#repo_status_clean? (instance method)">- (Boolean) <strong>repo_status_clean?</strong>(repo, cookbook) </a>



  </span>









    <span class="summary_desc"><div class='inline'></div></span>

</li>


        <li class="public ">
  <span class="summary_signature">

      <a href="#run-instance_method" title="#run (instance method)">- (Object) <strong>run</strong> </a>



  </span>









    <span class="summary_desc"><div class='inline'></div></span>

</li>


    </ul>










  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>


      <div class="method_details first">
  <h3 class="signature first" id="repo_cleanup-instance_method">

    - (<tt>Object</tt>) <strong>repo_cleanup</strong>(repo)





</h3><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


88
89
90
91
92
93
94
95
96
97
98
99
100</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/chef/knife/github_cleanup.rb', line 88</span>

<span class='kw'>def</span> <span class='id identifier rubyid_repo_cleanup'>repo_cleanup</span><span class='lparen'>(</span><span class='id identifier rubyid_repo'>repo</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_cookbook_path'>cookbook_path</span> <span class='op'>=</span> <span class='id identifier rubyid_config'>config</span><span class='lbracket'>[</span><span class='symbol'>:cookbook_path</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='const'>Chef</span><span class='op'>::</span><span class='const'>Config</span><span class='lbracket'>[</span><span class='symbol'>:cookbook_path</span><span class='rbracket'>]</span>
  <span class='id identifier rubyid_cookbook'>cookbook</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='id identifier rubyid_cookbook_path'>cookbook_path</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='comma'>,</span><span class='id identifier rubyid_repo'>repo</span><span class='rparen'>)</span>
  <span class='kw'>if</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_exists?'>exists?</span><span class='lparen'>(</span><span class='id identifier rubyid_cookbook'>cookbook</span><span class='rparen'>)</span>
    <span class='kw'>if</span> <span class='id identifier rubyid_repo_status_clean?'>repo_status_clean?</span><span class='lparen'>(</span><span class='id identifier rubyid_repo'>repo</span><span class='comma'>,</span> <span class='id identifier rubyid_cookbook'>cookbook</span><span class='rparen'>)</span>
      <span class='comment'># delete the repo
</span>      <span class='id identifier rubyid_ui'>ui</span><span class='period'>.</span><span class='id identifier rubyid_info'>info</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Processing [D] </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_repo'>repo</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
      <span class='const'>FileUtils</span><span class='period'>.</span><span class='id identifier rubyid_remove_entry'>remove_entry</span><span class='lparen'>(</span><span class='id identifier rubyid_cookbook'>cookbook</span><span class='rparen'>)</span>
    <span class='kw'>end</span>
  <span class='kw'>else</span>
    <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>cannot find repo path for: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_repo'>repo</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_config'>config</span><span class='lbracket'>[</span><span class='symbol'>:all</span><span class='rbracket'>]</span>
  <span class='kw'>end</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>

      <div class="method_details ">
  <h3 class="signature " id="repo_status_clean?-instance_method">

    - (<tt>Boolean</tt>) <strong>repo_status_clean?</strong>(repo, cookbook)





</h3><div class="docstring">
  <div class="discussion">


  </div>
</div>
<div class="tags">

<p class="tag_title">Returns:</p>
<ul class="return">

    <li>


        <span class='type'>(<tt>Boolean</tt>)</span>



    </li>

</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/chef/knife/github_cleanup.rb', line 102</span>

<span class='kw'>def</span> <span class='id identifier rubyid_repo_status_clean?'>repo_status_clean?</span><span class='lparen'>(</span><span class='id identifier rubyid_repo'>repo</span><span class='comma'>,</span> <span class='id identifier rubyid_cookbook'>cookbook</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_shell_out!'>shell_out!</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>git fetch</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='symbol'>:cwd</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_cookbook'>cookbook</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_status'>status</span> <span class='op'>=</span> <span class='id identifier rubyid_shell_out!'>shell_out!</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>git status</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='symbol'>:cwd</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_cookbook'>cookbook</span><span class='rparen'>)</span>
  <span class='kw'>unless</span> <span class='id identifier rubyid_status'>status</span><span class='period'>.</span><span class='id identifier rubyid_stdout'>stdout</span> <span class='op'>==</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'># On branch master\nnothing to commit (working directory clean)\n</span><span class='tstring_end'>&quot;</span></span>
    <span class='id identifier rubyid_ui'>ui</span><span class='period'>.</span><span class='id identifier rubyid_info'>info</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Processing [C] </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_repo'>repo</span><span class='rbrace'>}</span><span class='tstring_content'> (Action needed!)</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
    <span class='id identifier rubyid_status'>status</span><span class='period'>.</span><span class='id identifier rubyid_stdout'>stdout</span><span class='period'>.</span><span class='id identifier rubyid_lines'>lines</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_l'>l</span><span class='op'>|</span> <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_l'>l</span><span class='period'>.</span><span class='id identifier rubyid_sub'>sub</span><span class='lparen'>(</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>    </span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='rbrace'>}</span>
    <span class='kw'>return</span> <span class='kw'>false</span>
  <span class='kw'>end</span>
  <span class='id identifier rubyid_log'>log</span> <span class='op'>=</span> <span class='id identifier rubyid_shell_out!'>shell_out!</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>git log --branches --not --remotes --simplify-by-decoration --decorate --oneline</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='symbol'>:cwd</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_cookbook'>cookbook</span><span class='rparen'>)</span>
  <span class='kw'>unless</span> <span class='id identifier rubyid_log'>log</span><span class='period'>.</span><span class='id identifier rubyid_stdout'>stdout</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
    <span class='id identifier rubyid_ui'>ui</span><span class='period'>.</span><span class='id identifier rubyid_info'>info</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Processing [B] </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_repo'>repo</span><span class='rbrace'>}</span><span class='tstring_content'> (Action needed!)</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
    <span class='id identifier rubyid_ui'>ui</span><span class='period'>.</span><span class='id identifier rubyid_info'>info</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>    Please check your branches, one of them has unsaved changes</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
    <span class='id identifier rubyid_log'>log</span><span class='period'>.</span><span class='id identifier rubyid_stdout'>stdout</span><span class='period'>.</span><span class='id identifier rubyid_lines'>lines</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_l'>l</span><span class='op'>|</span> <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_l'>l</span><span class='period'>.</span><span class='id identifier rubyid_sub'>sub</span><span class='lparen'>(</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>    </span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='rbrace'>}</span>
    <span class='kw'>return</span> <span class='kw'>false</span>
  <span class='kw'>end</span>
  <span class='kw'>return</span> <span class='kw'>true</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>

      <div class="method_details ">
  <h3 class="signature " id="run-instance_method">

    - (<tt>Object</tt>) <strong>run</strong>





</h3><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/chef/knife/github_cleanup.rb', line 57</span>

<span class='kw'>def</span> <span class='id identifier rubyid_run'>run</span>

  <span class='comment'>#executing shell commands
</span>  <span class='id identifier rubyid_extend'>extend</span> <span class='const'>Chef</span><span class='op'>::</span><span class='const'>Mixin</span><span class='op'>::</span><span class='const'>ShellOut</span>

  <span class='comment'># validate base options from base module.
</span>  <span class='id identifier rubyid_validate_base_options'>validate_base_options</span>

  <span class='comment'># Display information if debug mode is on.
</span>  <span class='id identifier rubyid_display_debug_info'>display_debug_info</span>

  <span class='comment'># Gather all repo information from github.
</span>  <span class='id identifier rubyid_all_repos'>all_repos</span> <span class='op'>=</span> <span class='id identifier rubyid_get_all_repos'>get_all_repos</span><span class='lparen'>(</span><span class='ivar'>@github_organizations</span><span class='period'>.</span><span class='id identifier rubyid_reverse'>reverse</span><span class='rparen'>)</span>

  <span class='comment'># Get all chef cookbooks and versions (hopefully chef does the error handeling).
</span>  <span class='id identifier rubyid_cookbooks'>cookbooks</span> <span class='op'>=</span> <span class='id identifier rubyid_rest'>rest</span><span class='period'>.</span><span class='id identifier rubyid_get_rest'>get_rest</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>/cookbooks?num_version=1</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>

  <span class='comment'># Get the cookbook names from the command line
</span>  <span class='ivar'>@cookbook_name</span> <span class='op'>=</span> <span class='id identifier rubyid_name_args'>name_args</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span> <span class='kw'>unless</span> <span class='id identifier rubyid_name_args'>name_args</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
  <span class='kw'>if</span> <span class='ivar'>@cookbook_name</span>
    <span class='comment'># repo = all_repos.select { |k,v| v[&quot;name&quot;] == @cookbook_name }
</span>    <span class='id identifier rubyid_repo_cleanup'>repo_cleanup</span><span class='lparen'>(</span><span class='ivar'>@cookbook_name</span><span class='rparen'>)</span>
  <span class='kw'>elsif</span> <span class='id identifier rubyid_config'>config</span><span class='lbracket'>[</span><span class='symbol'>:all</span><span class='rbracket'>]</span>
    <span class='id identifier rubyid_cookbooks'>cookbooks</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span>
      <span class='id identifier rubyid_repo_cleanup'>repo_cleanup</span><span class='lparen'>(</span><span class='id identifier rubyid_c'>c</span><span class='rparen'>)</span>
    <span class='kw'>end</span>
  <span class='kw'>else</span>
    <span class='const'>Chef</span><span class='op'>::</span><span class='const'>Log</span><span class='period'>.</span><span class='id identifier rubyid_error'>error</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Please specify a repo name</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
  <span class='kw'>end</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>

  </div>

</div>

    <div id="footer">
  Generated on Wed Oct 30 21:59:26 2013 by
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.8.7.2 (ruby-1.9.3).
</div>

  </body>
</html>